//
//  LTFilesListViewController.swift
//  WIFISend
//
//  Created by lete on 2020/7/21.
//  Copyright © 2020 lete. All rights reserved.
//

import UIKit

class LTFilesListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    
    @IBOutlet weak var tableView: UITableView!
    
    var filesArr:[String] = [String]()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        refreshData()
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return filesArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "LTFilesListCell") as! LTFilesListCell
        cell.nameL.text = filesArr[indexPath.row]
        return cell
    }
    @IBAction func refreshBtn(_ sender: Any) {
        
        refreshData()
    }
    
    
    func refreshData() {
        let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        do {
            let arr = try  FileManager.default.contentsOfDirectory(atPath: documentsPath.path)
            filesArr = arr
            self.tableView.reloadData()
        } catch  {
            print("获取失败")
        }
    }
}
